
#include "Histogram.h"
#include <QPalette>



//-------------------------------------

Histogram::Histogram( const QString & title, const QColor & symbolColor ):
    QwtPlotHistogram( title )
{
    setStyle( QwtPlotHistogram::Columns );

    setColor( symbolColor );
}

//-------------------------------------

void Histogram::setColor( const QColor & symbolColor )
{
    QColor color = symbolColor;
    color.setAlpha( 180 );

    setPen( QPen( Qt::black ) );
    setBrush( QBrush( color ) );

    QwtColumnSymbol *symbol = new QwtColumnSymbol( QwtColumnSymbol::Box );
    symbol->setFrameStyle( QwtColumnSymbol::Raised );
    symbol->setLineWidth( 2 );
    symbol->setPalette( QPalette( color ) );
    setSymbol( symbol );
}

//-------------------------------------

void Histogram::setValues( uint numValues, const float * values )
{
    QVector< QwtIntervalSample > samples( numValues );
    for ( uint i = 0; i < numValues; i++ )
    {
        QwtInterval interval( float( i ), i + 1.0 );
        interval.setBorderFlags( QwtInterval::ExcludeMaximum );

        samples[i] = QwtIntervalSample( values[i], interval );
    }

    setData( new QwtIntervalSeriesData( samples ) );
}

//-------------------------------------
